package com.mj;

import com.mj.dao.BookDao;
import com.mj.entity.Book;
import com.mj.mapper.BookMapper;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class Demo {
    @Test
    public void dao(){
        ClassPathXmlApplicationContext ct = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookDao bd = ct.getBean(BookDao.class);//这里使用dao其实和之前的bookmapper一样，只不过dao自动装配了，dao里面引用了bookmapper里面的方法
        Book book = bd.queryById(4);
        System.out.println(book);
    }
    @Test
    public void tt(){
        ClassPathXmlApplicationContext ct = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookMapper bm = ct.getBean(SqlSession.class).getMapper(BookMapper.class);//这里走的是事务，就不需要像sqlsession进行提交了
        //Book bk = bm.queryById(3);
        //System.out.println(bk);
        //bk.setName("呼啸山庄");
        //bk.setPrice(300);
        //bk.setDate(new Date());
        //bm.insert(bk);
        //List<Map<String,Object>> lm = bm.queryAll();
        //for (Map<String,Object> m : lm){
        //   System.out.println(m);
        //}
    }
}
